package com.ruoyi.jiajia.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.JiajiaOrderSeparateAccounts;
import com.ruoyi.system.domain.vo.JiajiaOrderSeparateAccountsVo;
import com.ruoyi.system.service.IJiajiaOrderSeparateAccountsService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 订单分账流水Controller
 * 
 * @author ruoyi
 * @date 2025-04-01
 */
@Controller
@RequestMapping("/jiajia/accounts")
public class JiajiaOrderSeparateAccountsController extends BaseController
{
    private String prefix = "jiajia/accounts";

    @Autowired
    private IJiajiaOrderSeparateAccountsService jiajiaOrderSeparateAccountsService;

    @RequiresPermissions("jiajia:accounts:view")
    @GetMapping()
    public String accounts()
    {
        return prefix + "/accounts";
    }

    /**
     * 查询订单分账流水列表
     */
    @RequiresPermissions("jiajia:accounts:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(JiajiaOrderSeparateAccounts jiajiaOrderSeparateAccounts)
    {
        startPage();
        List<JiajiaOrderSeparateAccountsVo> list = jiajiaOrderSeparateAccountsService.selectJiajiaOrderSeparateAccountsList(jiajiaOrderSeparateAccounts);
        return getDataTable(list);
    }

    /**
     * 导出订单分账流水列表
     */
    @RequiresPermissions("jiajia:accounts:export")
    @Log(title = "订单分账流水", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(JiajiaOrderSeparateAccounts jiajiaOrderSeparateAccounts)
    {
        List<JiajiaOrderSeparateAccountsVo> list = jiajiaOrderSeparateAccountsService.selectJiajiaOrderSeparateAccountsList(jiajiaOrderSeparateAccounts);
        ExcelUtil<JiajiaOrderSeparateAccountsVo> util = new ExcelUtil<JiajiaOrderSeparateAccountsVo>(JiajiaOrderSeparateAccountsVo.class);
        return util.exportExcel(list, "订单分账流水数据");
    }

    /**
     * 新增订单分账流水
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存订单分账流水
     */
    @RequiresPermissions("jiajia:accounts:add")
    @Log(title = "订单分账流水", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(JiajiaOrderSeparateAccounts jiajiaOrderSeparateAccounts)
    {
        return toAjax(jiajiaOrderSeparateAccountsService.insertJiajiaOrderSeparateAccounts(jiajiaOrderSeparateAccounts));
    }

    /**
     * 修改订单分账流水
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        JiajiaOrderSeparateAccounts jiajiaOrderSeparateAccounts = jiajiaOrderSeparateAccountsService.selectJiajiaOrderSeparateAccountsById(id);
        mmap.put("jiajiaOrderSeparateAccounts", jiajiaOrderSeparateAccounts);
        return prefix + "/edit";
    }

    /**
     * 修改保存订单分账流水
     */
    @RequiresPermissions("jiajia:accounts:edit")
    @Log(title = "订单分账流水", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(JiajiaOrderSeparateAccounts jiajiaOrderSeparateAccounts)
    {
        return toAjax(jiajiaOrderSeparateAccountsService.updateJiajiaOrderSeparateAccounts(jiajiaOrderSeparateAccounts));
    }

    /**
     * 删除订单分账流水
     */
    @RequiresPermissions("jiajia:accounts:remove")
    @Log(title = "订单分账流水", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(jiajiaOrderSeparateAccountsService.deleteJiajiaOrderSeparateAccountsByIds(ids));
    }
}
